<?php

namespace app\validate\admin;

use think\Validate;

class RoleValidate extends Validate
{
	protected $rule = [
        'name'   => 'require|length:2,24|regex:/^[\x{4e00}-\x{9fa5}a-zA-Z0-9_]+$/u',
        'status' => 'require',
        '_token' => 'require|token:_token',
    ];

    protected $message = [
        'name.require'     => '角色名必须填写',
        'name.length'      => '角色名过短或过长3~20',
        'name.regex'        => '角色名格式不正确',
        'slug.require'     => '标识必须填写',
        'slug.length'      => '标识过短或过长3~20',
        'slug.regex'        => '标识格式不正确',
        'status.require'   => '状态必须选择',
        '_token.require' => 'toke令牌为空',
        'auth.array' => '权限类型错误array',
        'id.require' => 'ID为空',
        'id.number' => 'ID不是数字类型',
    ];

    public function sceneCreate()
    {
        return $this->append(['slug' => 'require|length:2,16|regex:/^[a-zA-Z_]+[a-zA-Z0-9_]+$/u']);
    }

    public function sceneAuth()
    {
        return $this->append(['id' => 'require|number', 'auth' => 'array'])->only(['_token', 'id', 'auth']);
    }
}
